<?php

namespace App\Models;

use App\Services\TreeService;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Dcat\Admin\Traits\ModelTree;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;

class ActivityAreaSetting extends Model
{
    use HasDateTimeFormatter;
    use SoftDeletes;
    use ModelTree;

    protected $table = 'activity_area_setting';
    
    protected $fillable = [
        'id',
        'act_id',
        'img',
        'title',
        'parent_id',
        'order',
        'created_at',
        'updated_at',
        'deleted_at',
    ];

    protected $hidden = [
        'act_id',
        'img',
        'created_at',
        // 'updated_at',
        'deleted_at'
    ];

    /**
     * 获取赛区分类
     *
     * @Author hechengwei
     * @email chichiooo@sina.com
     * @DateTime 2023-02-06
     * @param int $act_id
     * @return void
     */
    public static function getDivisionArea($act_id)
    {
        $array = self::where('act_id', $act_id)->where('parent_id', '<>', 0)->get();
        $array->makeHidden('updated_at');
        $array = $array->toArray();
        $tree = list_to_tree($array, '1', 'parent_id', 'id', 'child');
        return $tree;
    }
}
